local hx__yuzhan = fk.CreateSkill {
  name = "hx__yuzhan",
}

hx__yuzhan:addEffect(fk.Damage, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__yuzhan.name) and data.card and ( data.card.trueName == "slash" or data.card.trueName == "duel")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = {"hx__yuzhan_recover", "hx__yuzhan_get"}
    local choices = player:getAvailableEquipSlots()
    if #choices > 0 then 
      table.insert(choice, "hx__yuzhan_all")
    end
    local choose = room:askToChoice(player, {
       choices = choice,
       skill_name = hx__yuzhan.name,
    })
    if choose == "hx__yuzhan_recover" or choose == "hx__yuzhan_all" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = hx__yuzhan.name
      })
    end
    if choose == "hx__yuzhan_get" or choose == "hx__yuzhan_all" then
      local card = room:getCardsFromPileByRule(".|.|.|.|.|equip", 1, "allPiles")
      if #card > 0 then
        room:moveCards({
          ids = card,
          to = player,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonJustMove,
          proposer = player,
          skillName = self.name,
        })
      end
    end
    if choose == "hx__yuzhan_all" then
      local choice = room:askToChoice(player,{
        choices = choices,
        skill_name = hx__yuzhan.name,
        prompt = "#hx__yuzhan-ask",
      })
      room:abortPlayerArea(player, choice)
    end
  end,
})

return hx__yuzhan